package org.sunrise.game.common.network.start;

import org.sunrise.game.common.network.client.BaseClientManager;
import org.sunrise.game.common.network.message.BaseMessage;
import org.sunrise.game.common.network.server.BaseServerManager;
import org.sunrise.game.common.utils.Utils;

public class MixtureStartUp {
    public static void main(String[] args) throws InterruptedException {
        var server1 = BaseServerManager.createBaseServer("server-node1");
        server1.startListen(Utils.getLocalIpAddress(), 1010);

        var client1 = BaseClientManager.createBaseClient("client-node1");
        client1.connectBlock(Utils.getLocalIpAddress(), 1010);

        // 1.未指定此消息所属的服务端节点id
        // 使用server1.sendToClient发送
        var sendMsg1 = new BaseMessage("", client1.getNodeId(), 0, "s->c 1");
        server1.sendToClient(sendMsg1); //发送成功，由server1发送给client1

        // 2.未指定此消息所属的服务端节点id
        // 使用BaseServerManager.sendToClient发送
        var sendMsg2 = new BaseMessage("", client1.getNodeId(), 0, "s->c 2");
        BaseServerManager.sendToClient(sendMsg2); //发送失败，并不知道此消息由谁发出

        // 3.指定此消息所属的服务端节点id
        // 使用server1.sendToClient发送
        var sendMsg3 = new BaseMessage(server1.getNodeId(), client1.getNodeId(), 0, "s->c 3");
        server1.sendToClient(sendMsg3); //发送成功，由server1发送给client1

        // 4.指定此消息所属的服务端节点id
        // 使用BaseServerManager.sendToClient发送
        var sendMsg4 = new BaseMessage(server1.getNodeId(), client1.getNodeId(), 0, "s->c 4");
        BaseServerManager.sendToClient(sendMsg4); //发送成功，由server1发送给client1
    }
}
